﻿/*******************************************************************************************************************************************
Modification History:
********************************************************************************************************************************************
Date		Author		    Description
********************************************************************************************************************************************
05/07/2011	Brian Kuhn	    Created Heartbeat class
*******************************************************************************************************************************************/
using System;
using System.ComponentModel.Composition;
using System.Runtime.Serialization;

namespace Concise.ServiceModel.Channels
{
    /// <summary>
    /// Represents a notification message sent by the message bus to its nodes.
    /// </summary>
    [Export(typeof(IMessage)), DataContract()]
    public class Heartbeat : IMessage
    {
        //=======================================================================================================
        //  Constructors
        //=======================================================================================================
        #region Heartbeat()
        /// <summary>
        /// Initializes a new instance of the <see cref="Heartbeat"/> class.
        /// </summary>
        public Heartbeat()
        {

        }
        #endregion

        #region Heartbeat(DateTime sentAt)
        /// <summary>
        /// Initializes a new instance of the <see cref="Heartbeat"/> class 
        /// using the specified date and time at which the heartbeat was sent.
        /// </summary>
        /// <param name="sentAt">The date and time at which the heartbeat was sent at.</param>
        public Heartbeat(DateTime sentAt)
        {
            this.SentAt = sentAt;
        }
        #endregion

        //=======================================================================================================
        //  Public Properties
        //=======================================================================================================
        #region SentAt
        /// <summary>
        /// Gets or sets the date and time at which this heartbeat was sent at.
        /// </summary>
        /// <value>
        /// A <see cref="DateTime"/> that represents the date and time at which this heartbeat was sent at. 
        /// The default value is <see cref="DateTime.UtcNow"/>.
        /// </value>
        [DataMember()]
        public DateTime SentAt
        {
            get
            {
                return _heartbeatSentAt;
            }

            set
            {
                if (!DateTime.Equals(_heartbeatSentAt, value))
                {
                    _heartbeatSentAt = value;
                }
            }
        }
        private DateTime _heartbeatSentAt = DateTime.UtcNow;
        #endregion
    }
}
